package com.etc.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.etc.service.impl.MessageServiceImpl;
import com.etc.service1.MessageServiceDao;
import com.etc.util.PageTool;
import com.etc.entity.*;
import java.util.*;
/**
 * Servlet implementation class ListMessageServle
 */
@WebServlet("/ListMessageServlet")
public class ListMessageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ListMessageServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String type=request.getParameter("type");
		int pageindex=Integer.valueOf(request.getParameter("pageIndex"));
		int pagesize = 10;
		MessageServiceDao ms = new MessageServiceImpl();
		List<Message> list = ms.searchAllMessage(pageindex,pagesize,type);
		
		PageTool<Message> pageMessage = new PageTool<Message>();
		pageMessage.setList(list);
		pageMessage.setPageIndex(pageindex);		
		pageMessage.setPageSize(pagesize);
		Long result=ms.countAll();
		pageMessage.setTotalCount(result.intValue());
		
		request.setAttribute("listMessage", pageMessage);
		request.getRequestDispatcher("message-list.jsp").forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
